package com.seamtop.cuber.common.util;

import com.seamtop.cuber.common.entriy.CuberCounter;
import com.seamtop.cuber.common.entriy.TableOperatorBean;
import com.seamtop.cuber.common.entriy.TableOperatorType;
import com.seamtop.cuber.common.metadata.Column;
import com.seamtop.cuber.common.metadata.RowKey;
import com.seamtop.cuber.common.metadata.TableMetaData;

import java.util.HashMap;

/**
 * Created by zongjunfeng on 2015/10/12.
 */
public class EnvBuilder {

    public static TableMetaData combineCounterMData(CuberCounter cuberCounter){
        String tableName = cuberCounter.getCounterName();
        TableMetaData tableMetaData = new TableMetaData();
        RowKey rowKey = new RowKey();
        rowKey.setKeyGenerator("getCounterKey");
        rowKey.setKeyName("rowKey");
        tableMetaData.setRowKey(rowKey);
        HashMap<String,Column> columnMap = new HashMap<String, Column>();
        Column column = new Column();
        column.setMatch("v");
        column.setFamilyName("mf");
        column.setColumnName("value");
        column.setIsIncrement(true);
        column.setColumnType(3);
        column.setColumnDesc("long");
        columnMap.put("value", column);
        tableMetaData.setTableName(tableName);
        tableMetaData.setIsVirtualTable(true);
        tableMetaData.setTableId(cuberCounter.getCounterId());
        tableMetaData.setTablePrefix(cuberCounter.getCounterId());
        tableMetaData.setPrimaryTableName("VT_PRIMARY");
        tableMetaData.setColumnMap(columnMap);
        tableMetaData.setIsCustomCounterTable(true);
        return tableMetaData;
    }

    public static TableOperatorBean combineCounterOperatorBean(CuberCounter cuberCounter){
        String tableName = cuberCounter.getCounterName();
        TableOperatorBean tableOperatorBean = new TableOperatorBean();
        tableOperatorBean.setOperatorTable(tableName);
        String operatorName = "INCREMENT"+"_"+tableName;
        tableOperatorBean.setOperatorName(operatorName);
        tableOperatorBean.setOperatorType(TableOperatorType.TABLE_OPERATOR_TYPE_INCREMENT);
        return tableOperatorBean;
    }
}
